﻿using Newtonsoft.Json;

namespace FrameWork.Util.Expansion
{
    /// <summary>
    /// 通用扩展方法存放位置
    /// </summary>
    public static class CommonEx
    {
        /// <summary>
        /// 转换成紧凑Json字符串
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ToJson(this object obj)
        {
            if (obj == null) return "";
            return JsonConvert.SerializeObject(obj);
        }
        
        /// <summary>
        /// 转换成格式化Json字符串
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string ToJsonIndented(this object obj)
        {
            if (obj == null) return "";
            return JsonConvert.SerializeObject(obj, Formatting.Indented);
        }
    }
}